package com.persondemo.videoappliction;

import android.app.Application;
import android.os.Build;
import android.os.StrictMode;
import android.util.Log;

import com.google.android.gms.ads.MobileAds;
import com.lzy.ninegrid.NineGridView;
import com.persondemo.videoappliction.component.ApplicationComponent;
import com.persondemo.videoappliction.component.DaggerApplicationComponent;
import com.persondemo.videoappliction.module.ApplicationModule;
import com.persondemo.videoappliction.module.HttpModule;
import com.persondemo.videoappliction.utils.ContextUtils;
import com.persondemo.videoappliction.utils.PicassoImageLoader;
import com.squareup.leakcanary.LeakCanary;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.smtt.sdk.QbSdk;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;

import org.litepal.LitePal;
import org.litepal.LitePalApplication;

import cn.bingoogolapple.swipebacklayout.BGASwipeBackManager;


/**
 * Created by Administrator on 2018/3/19.
 */
public class MyApp extends LitePalApplication {
    private ApplicationComponent mApplicationComponent;
    private static MyApp sMyApp;
    public static int width = 0;
    public static int height = 0;

    @Override
    public void onCreate() {
        super.onCreate();
        sMyApp = this;
        BGASwipeBackManager.getInstance().init(this);
        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .httpModule(new HttpModule())
                .build();
        LitePal.initialize(this);
        width = ContextUtils.getSreenWidth(MyApp.getContext());
        height = ContextUtils.getSreenHeight(MyApp.getContext());
        MobclickAgent.setDebugMode(true);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
        //初始化ShareSDK
        UMConfigure.init(this, "5ac9904a8f4a9d65c10000ad"
                , "umeng02", UMConfigure.DEVICE_TYPE_PHONE, "");
        UMConfigure.setLogEnabled(true);
        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
            @Override
            public void onViewInitFinished(boolean arg0) {
                com.tencent.smtt.sdk.WebView webView = new com.tencent.smtt.sdk.WebView(MyApp.getContext());
                int width = webView.getView().getWidth();
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
//x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);
        //bugly
        CrashReport.initCrashReport(getApplicationContext(), "c767d6a46c", false);
        //手机7.0以上拍照
        if (Build.VERSION.SDK_INT > 21) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            builder.detectFileUriExposure();
        }
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            // This process is dedicated to LeakCanary for heap analysis.
//            // You should not init your app in this process.
//            return;
//        }
//        LeakCanary.install(this);
        NineGridView.setImageLoader(new PicassoImageLoader());


    }

    public static MyApp getInstance() {
        return sMyApp;
    }

    public ApplicationComponent getApplicationComponent() {
        return mApplicationComponent;
    }
}

